package com.crazyant;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Inventory extends Activity {
	
	BitmapFactory.Options options;
	Resources resources;
	private int idinv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        GV.Instancies.inventory = (InventoryView)findViewById(R.id.inventoryview);
//        resources = GV.Instancies.inventory.getResources();
        resources =  GV.Instancies.respest;
        options = new BitmapFactory.Options();
		options.inPreferredConfig = Bitmap.Config.ARGB_8888;
		
        if(GV.BBDD.r == 1) idinv = GV.BBDD.dbhandler.getContact(GV.BBDD.user).getInv();
		
      //TABLA MUNDO 1
        TableLayout table = new TableLayout(this);
        table.setStretchAllColumns(true);  
        table.setShrinkAllColumns(true);  
        TableRow rowTitle_cascos = new TableRow(this);
        rowTitle_cascos.setGravity(Gravity.CENTER_HORIZONTAL);
        TableRow rowTitle_cuerpo = new TableRow(this);
        rowTitle_cuerpo.setGravity(Gravity.CENTER_HORIZONTAL);
        TableRow rowTitle_botas = new TableRow(this);
        rowTitle_botas.setGravity(Gravity.CENTER_HORIZONTAL);
        TableRow rowTitle_color = new TableRow(this);
        rowTitle_color.setGravity(Gravity.CENTER_HORIZONTAL);
        
        TableRow cascos = new TableRow(this);
        TableRow cuerpo = new TableRow(this);
        TableRow botas = new TableRow(this);
        TableRow color = new TableRow(this);
        
        //TITULOS
        TextView title_cascos = new TextView(this);
        title_cascos.setText("Cascos");
        title_cascos.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        title_cascos.setGravity(Gravity.CENTER);
        title_cascos.setTypeface(Typeface.SERIF, Typeface.BOLD);
        title_cascos.setTextColor(Color.parseColor("#FF0000"));
        TableRow.LayoutParams params_cascos = new TableRow.LayoutParams();
        params_cascos.span = 3;
        rowTitle_cascos.addView(title_cascos, params_cascos);
        TextView title_cuerpo = new TextView(this);
        title_cuerpo.setText("Cuerpo");
        title_cuerpo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        title_cuerpo.setGravity(Gravity.CENTER);
        title_cuerpo.setTypeface(Typeface.SERIF, Typeface.BOLD);
        title_cuerpo.setTextColor(Color.parseColor("#FF0000"));
        TableRow.LayoutParams params_cuerpo = new TableRow.LayoutParams();
        params_cuerpo.span = 3;
        rowTitle_cuerpo.addView(title_cuerpo, params_cuerpo);
        TextView title_botas = new TextView(this);
        title_botas.setText("Botas");
        title_botas.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        title_botas.setGravity(Gravity.CENTER);
        title_botas.setTypeface(Typeface.SERIF, Typeface.BOLD);
        title_botas.setTextColor(Color.parseColor("#FF0000"));
        TableRow.LayoutParams params_botas = new TableRow.LayoutParams();
        params_botas.span = 3;
        rowTitle_botas.addView(title_botas, params_botas);
        TextView title_color = new TextView(this);
        title_color.setText("Color");
        title_color.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        title_color.setGravity(Gravity.CENTER);
        title_color.setTypeface(Typeface.SERIF, Typeface.BOLD);
        title_color.setTextColor(Color.parseColor("#FF0000"));
        TableRow.LayoutParams params_color = new TableRow.LayoutParams();
        params_color.span = 3;
        rowTitle_color.addView(title_color, params_color);
        
        int cont = 1;
        int i = 0;
        
        while(i < 12) {
        	ImageView casco1 = new ImageView(this);
        	if(i <= idinv) {
        		String icon = "casco"+idinv;
        		int rest = resources.getIdentifier(icon, "drawable", "com.crazyant");
        		casco1.setImageBitmap(BitmapFactory.decodeResource(resources, rest, options));
        	}
        	else {
        		String icon = "inv0";
        		casco1 = new ImageView(this);
        		int rest = resources.getIdentifier(icon, "drawable", "com.crazyant");
        		casco1.setImageBitmap(BitmapFactory.decodeResource(resources, rest, options));
        	}
        	++i;
        	cascos.addView(casco1);
        	
        	ImageView cuerpo1 = new ImageView(this);
        	if(i <= idinv) {
        		String icon = "cuerpo"+idinv;
        		int rest = resources.getIdentifier(icon, "drawable", "com.crazyant");
        		casco1.setImageBitmap(BitmapFactory.decodeResource(resources, rest, options));
        	}
        	else {
        		String icon = "inv0";
        		cuerpo1 = new ImageView(this);
        		int rest = resources.getIdentifier(icon, "drawable", "com.crazyant");
        		cuerpo1.setImageBitmap(BitmapFactory.decodeResource(resources, rest, options));
        	}
        	++i;
        	cuerpo.addView(cuerpo1);
        	
        	ImageView botas1 = new ImageView(this);
        	if(i <= idinv) {
        		String icon = "botas"+idinv;
        		int rest = resources.getIdentifier(icon, "drawable", "com.crazyant");
        		botas1.setImageBitmap(BitmapFactory.decodeResource(resources, rest, options));
        	}
        	else {
        		String icon = "inv0";
        		botas1 = new ImageView(this);
        		int rest = resources.getIdentifier(icon, "drawable", "com.crazyant");
        		botas1.setImageBitmap(BitmapFactory.decodeResource(resources, rest, options));
        	}
        	++i;
        	botas.addView(botas1);
        }
        
        ImageView prota0 = new ImageView(this);
        prota0.setImageBitmap(BitmapFactory.decodeResource(resources, R.drawable.prota0, options));
        ImageView prota1 = new ImageView(this);
        prota1.setImageBitmap(BitmapFactory.decodeResource(resources, R.drawable.prota1, options));
        ImageView prota2 = new ImageView(this);
        prota2.setImageBitmap(BitmapFactory.decodeResource(resources, R.drawable.prota2, options));
        ImageView prota3 = new ImageView(this);
        prota3.setImageBitmap(BitmapFactory.decodeResource(resources, R.drawable.prota3, options));
        color.addView(prota0);
        color.addView(prota1);
        color.addView(prota2);
        color.addView(prota3);
        
        //anadimos titulo
        table.addView(rowTitle_cascos);
        table.addView(cascos);
        //anadimos titulos apartados
        table.addView(rowTitle_cuerpo);
        table.addView(cuerpo);
        table.addView(rowTitle_botas);
        table.addView(botas);
        table.addView(rowTitle_color);
        table.addView(color);
        
        
        setContentView(table);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_inventory, menu);
        return true;
    }

    public void acaba() {
    	finish();
    }
    
    @Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onResume() {
		super.onPostResume();
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
}
